/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ThreadConfig
 * Author:   pc
 * Date:     2019/9/5 15:04
 * Description: 线程配置
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.rabbitmqdemo.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.javassist.bytecode.analysis.Executor;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.lang.reflect.Method;

/**
 * 〈功能：〉<br>
 * 〈线程配置〉
 *
 * @author liuhaoran
 * @create 2019/9/5 15:04
 * @since 1.0.0
 */
@Configuration
@EnableAsync
@Slf4j
public class ThreadConfig implements AsyncConfigurer {
	/*@Slf4j
	public class ThreadConfig implements AsyncConfigurer {
		@Override
		public Executor getAsyncExecutor() {
			ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
			Integer corePoolSize = LocalHostUtil.getCorePoolSize();
			Integer maxPoolSize = LocalHostUtil.getMaxPoolSize();
			Integer queueCapacity = LocalHostUtil.getQueueCapacity();
			log.info("---------[多线程配置初始化]，最大核心线程数:{}，最大线程池数量:{},线程处理队列长度:{}", corePoolSize, maxPoolSize, queueCapacity);
			//核心线程数
			executor.setCorePoolSize(corePoolSize);
			//最大线程池数量
			executor.setMaxPoolSize(maxPoolSize);
			//线程处理队列长度
			executor.setQueueCapacity(queueCapacity);
			executor.initialize();
			return executor;
		}

		@Override
		public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
			log.info("-----------多线程异常handler------------");
			return new SpringAsyncExceptionHandler();
		}

		class SpringAsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
			@Override
			public void handleUncaughtException(Throwable ex, Method method, Object... params) {
				log.error("Asyn无返回异常：" + ex.getCause().getMessage() + method.getName() + params);
			}
		}@Configuration
	@EnableAsync
*/

	}